package demo.day11_CollectionAddpackage.List;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/2-08-02-14:57
 * @Description：demo.day11_CollectionAddpackage.List   Map集合
 */
/*
  Map集合 <key,value>
        key值不可重复
    linkedHashMap 存取顺序一致
 */
public class Map_use {
    public static void main(String[] args) {
        Map map = new HashMap<>();    //存储键值对
//        map.put(1,"a");
//        map.put(2,"c");
//        map.put(3,"c");
        map.put(null,null);
        map.put(null,null);
//        System.out.println(map);
//        String s = "dbfbdsvbskds";      //利用map获取字符串中每个字符的次数
//        for (int i = 0; i < s.length(); i++) {
//            char c = s.charAt(i);
//            if(map.containsKey(c)){
//                map.put(c,(int)map.get(c)+1);
//            }else{
//                map.put(c,1);
//            }
//        }
        //遍历map集合
//        for (Object o : map.keySet()) {
////            String str = (String)o;
//            char str = o.toString().charAt(0);
//            System.out.println(str + ": " + map.get(str));
//        }
        //第二种：
        Iterator<Map.Entry<Character,Integer>> it = map.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<Character,Integer> entry = it.next();
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}
